//
//  Shop_collectionViewCell.m
//  EggSteward
//
//  Created by 王道林 on 16/9/1.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "Shop_collectionViewCell.h"
#import "Masonry.h"
#import "BaseLabel.h"
#import "BaseButton.h"
#import "UIImageView+WebCache.h"
@interface Shop_collectionViewCell ()
@property (nonatomic, strong) UIImageView *imageview;
@property (nonatomic, strong) BaseLabel *lableName;
@property (nonatomic, strong) UIImageView *imageviewAgg;
@property (nonatomic, strong) BaseLabel *lableNumber;
@property (nonatomic, strong) BaseButton *buttonChange;
@end
@implementation Shop_collectionViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
        self.contentView.backgroundColor = [UIColor colorWithWhite:0.934 alpha:1.000];
    }
    return self;
}

- (void)createSubView
{
    _imageview = [[UIImageView alloc] init];
    [self.contentView addSubview:_imageview];
    
    _lableName = [[BaseLabel alloc] init];
    [self.contentView addSubview:_lableName];
    
    _imageviewAgg = [[UIImageView alloc] init];
    [self.contentView addSubview:_imageviewAgg];
    
    _lableNumber = [[BaseLabel alloc] init];
    [self.contentView addSubview:_lableNumber];
    
    _buttonChange = [BaseButton buttonWithType:UIButtonTypeSystem];
    _buttonChange.backgroundColor = [UIColor colorWithRed:1.000 green:0.225 blue:0.046 alpha:1.000];
    [_buttonChange setTitle:@"兑  换" forState:UIControlStateNormal];
    [_buttonChange setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _buttonChange.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.contentView addSubview:_buttonChange];
}


- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [_imageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top);
        make.left.mas_equalTo(self.contentView.mas_left);
        make.right.mas_equalTo(self.contentView.mas_right);
        make.height.mas_equalTo(self.contentView.mas_height).multipliedBy(0.6);
    }];
    
    [_lableName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left);
        make.top.mas_equalTo(_imageview.mas_bottom).mas_offset(10);
        make.width.mas_equalTo(self.contentView.mas_width).multipliedBy(0.8);
        make.height.mas_equalTo(self.contentView.mas_height).multipliedBy(0.1);
    }];
    
    [_imageviewAgg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).mas_offset(10);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).mas_offset(-15);
        make.width.mas_equalTo(self.contentView.mas_height).multipliedBy(0.1);
        make.height.mas_equalTo(self.contentView.mas_height).multipliedBy(0.1);
    }];
    
    [_lableNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_imageviewAgg.mas_right);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).mas_offset(-15);
        make.width.mas_equalTo(self.contentView.mas_width).multipliedBy(0.3);
        make.height.mas_equalTo(self.contentView.mas_height).multipliedBy(0.1);
    }];

    [_buttonChange mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-5);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).mas_offset(-5);
        make.top.mas_equalTo(_lableNumber.mas_top);
        make.width.mas_equalTo(self.contentView.mas_width).multipliedBy(0.3);
    }];

}

#pragma mark - set赋值
- (void)setShopModel:(ShopGoodModel *)shopModel
{
    _shopModel = shopModel;
    [_imageview sd_setImageWithURL:[NSURL URLWithString:_shopModel.pic] placeholderImage:[UIImage imageNamed:@"120"]];
    _lableName.text = _shopModel.goods_name;
    _lableNumber.text = _shopModel.money_need;
    _imageviewAgg.image = [UIImage imageNamed:@"jidan"];
}



@end
